package threadsafe;

class SaleTicket1 extends Thread{
    static int ticket = 100;
    boolean flag = true;
    @Override
    public void run() {
        while(flag){
            show();
        }

    }

    public void show(){
        synchronized (SaleTicket.class) {
            if (ticket > 0) {
                try{
                    Thread.sleep(10);
                }catch (Exception e){
                    e.printStackTrace();
                }

                System.out.println(Thread.currentThread().getName() + "票号为：" + ticket);
                ticket--;
            } else {
                flag = false;
            }
        }
    }
}

public class WindowTest1 {
    public static void main(String[] args){
        SaleTicket1 s1 = new SaleTicket1();
        SaleTicket1 s2 = new SaleTicket1();
        SaleTicket1 s3 = new SaleTicket1();

        s1.setName("窗口一");
        s2.setName("窗口二");
        s3.setName("窗口三");

        s1.start();
        s2.start();
        s3.start();



    }
}
